package practice1_100;

public class Practice331 {
    public boolean isValidSerialization(String preorder) {
        String[] a= preorder.split(",");
        TreeNode root=null;
        isSerialization(a,0,root);
        return false;
    }

    private boolean isSerialization(String[] strings,int index,TreeNode root) {
        if(index>strings.length-1) return true;
        if(!strings[index].equals("#")){
            int a=Integer.parseInt(strings[index]);
            root = new TreeNode(a);

        }else {
            root=null;
        }
        if (root!=null){
            isSerialization(strings,index+1,root.left);
            isSerialization(strings,index+2,root.right);
        }

return false;
    }

    public static void main(String[] args) {
        new Practice331().isValidSerialization("9,3,4,#,#,1,#,#,2,#,6,#,#");
    }
}
